# 上下文管理类
class MyFile(object):
    def __init__(self,filename):
        self.file_obj = open(filename)
    def __enter__(self):
        return self.file_obj

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.file_obj.close()

with MyFile('config.ini') as f:
    print(f.read())

print(f.read())
